<?php
/**
 * Created by jinqiang on 2024/7/12 16:52.
 * Copyright (c) 2024, Your Company. All rights reserved.
 */


namespace App\Http\Controllers\Produce;


use App\Http\Controllers\Controller;
use App\Http\Services\Produce\TagService;
use Illuminate\Http\Request;

class TagController extends Controller
{
    public function list(Request $request, TagService $tagService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $tagService->search($param);
        return result($res);
    }

    //吊牌确认列表
    public function checkList(Request $request, TagService $tagService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $tagService->searchCheck($param);
        return result($res);
    }

    public function del(Request $request, TagService $tagService)
    {
        $this->validate($request, [
            'id' => 'required'
        ]);
        $param = $request->all();
        $res = $tagService->del($param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }

    public function skuList(Request $request, TagService $tagService)
    {
        $this->validate($request, [
            'type_no' => 'required'
        ]);
        $param = $request->all();
        $res = $tagService->getSku($param['type_no']);
        return result($res);
    }

    public function save(Request $request, TagService $tagService)
    {
        $this->validate($request, [
            'data' => 'required'
        ]);
        $param = $request->all();
        $res = $tagService->save($param['data']);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }

    //吊牌确认--预览
    public function checkPreview(Request $request, TagService $tagService)
    {
        $this->validate($request, [
            'p_id' => 'required',//加工单id
            't_id' => 'required'//吊牌id
        ]);
        $param = $request->all();
        $res = $tagService->preview($param['p_id'], $param['t_id']);
        return result($res);
    }

    //吊牌确认--确认状态
    public function status(Request $request, TagService $tagService)
    {
        $this->validate($request, [
            'ids' => 'required',
            'status' => 'required'
        ]);
        $param = $request->all();
        $res = $tagService->checkStatus($param['ids'], $param['status']);
        return $res['code'] === 0 ? success("修改成功") : error($res['msg'], $res);
    }

    //吊牌确认--推送
    public function push(Request $request, TagService $tagService)
    {
        $this->validate($request, [
            'data' => 'required',
        ]);
        $param = $request->all();
        $res = $tagService->push(json_decode($param['data'], true));
        return $res['code'] === 0 ? success("推送成功") : error($res['msg'], $res);
    }
}
